// TODO: Extract this so the server only renders the HTML.
var li = $('li#comfy_cms_page_<%=@page.id%>');
li.find('.item .toggle').first().toggleClass('open');

<% if session[:cms_page_tree].member?(@page.id.to_s) %>
  if(!li.find('ul.children')[0]) {
    li.append('<ul class="children sortable pl-md-3"><%= escape_javascript(render partial: "index_branch", collection: @page.children) %></ul>');
    CMS.sortableList.dispose();
    CMS.sortableList.init();
  }
<% else %>
  li.find('ul.children').remove();
<% end %>
